package com.ymatou.iapi.livemanage.testcase;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livemanage.service.GetActivityInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.database.mongo.LiveBasicInfoWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.sqlwapper.YmtLiveWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;

public class Ts_GetActivityInfo {
	
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName =EnvSetup.getData("productsellername");
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播编辑加载查询");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new GetActivityInfoCall().getOpurl());
	}
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryCountryGroup() {
		Logger.start(true, "直播编辑加载查询");
		try{
			
			
			//1.创建将要开始的直播
			JSONObject createLiveReq = LiveCallService.createLiveBeginInFuture(sellerName,sellerId);
			int liveId = createLiveReq.getJSONObject("Data").getInt("ActivityId");
			
			//2. 查询直播
			GetActivityInfoCall getActivityInfoCall = new GetActivityInfoCall();
			getActivityInfoCall.setData(liveId, sellerId);
			getActivityInfoCall.callService();
			
			//检查返回码
			JSONObject activityRet = new JSONObject(getActivityInfoCall.getReturnData());
			Logger.verifyEquals(activityRet.getInt("Code"), 200, "响应报文-返回码");
			
			//检查返回数据
			JSONObject dataObj = activityRet.getJSONObject("Data");
			
			Logger.verifyEquals(dataObj.getInt("SellerId"), sellerId, "响应报文-用户ID");
			Logger.verifyEquals(dataObj.getInt("ActivityId"), liveId, "响应报文-直播ID");
			
			//Mongo check
			Map<String, Object>  tgtRetMap = new HashMap<String,Object>();
			
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				
				Map<String, Object> ret = new LiveBasicInfoWapper().getActivityId(liveId);
				
				
				tgtRetMap.put("ActivityId", liveId);
				tgtRetMap.put("Seller", sellerName);
				tgtRetMap.put("SellerId", sellerId);
				
				AssertService.assertResultEqual(tgtRetMap, ret);
			}
		
			
			//SQL check
			Map<String, Object> SqlRet = MapUtil.pojoToMap(new YmtLiveWapper().selectByLiveId(liveId));
			tgtRetMap.clear();
			tgtRetMap.put("iactivityid", liveId);
			tgtRetMap.put("ssellername", sellerName);
			tgtRetMap.put("isellerid", sellerId);
			AssertService.assertResultEqual(tgtRetMap, SqlRet);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	
	
	}
	
}
